/**
 * 
 * eui继承该类，在initUI中初始化组件以及调整UI的位置
 *
 */
abstract class BaseEuiView extends eui.Component {
    public constructor() {
        super();
        //必须卸载skinName前面
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onComplete,this);
        this.setSkinName();
    }
    
    protected setSkinName():void{
        this.skinName = this.exml();
    }
    
    /**
     * 设置缩放
     */
    public setScale(s: number) {//设置缩放 
        this.scaleX = s;
        this.scaleY = s;
    }
    
    /**
     * 对view进行scale
     */
    public setViewScale(view: egret.DisplayObject,scaleX: number,scaleY: number) {
        view.scaleX = scaleX;
        view.scaleY = scaleY;
    }
    
    /**
     * 设置锚点
     */
    public setAnchor(view: egret.DisplayObject,anchorX: number,anchorY: number) {
        view.anchorOffsetX = anchorX;
        view.anchorOffsetY = anchorY;
    }
    
    /** 同步或异步加载source资源 */
    public loadAsset(source: string,compFunc: Function,thisObject: any): void {
        Resource.loadAsset(source,compFunc,thisObject);
    }
    
    /** EUI 会在调用 setSkinPart()方法时自动调用此方法。 子类覆盖此方法，以在皮肤部件第一次附加时对其执行一些初始化操作，例如添加事件监听，赋值缓存的属性值等。  */
    protected partAdded(partName: string,instance: any): void {
        super.partAdded(partName,instance);
        Log.d(egret.getQualifiedClassName(this) + ":" + egret.getQualifiedClassName(instance) + ":partAdded");
    }
    
    /** 在 createChildren 的时候，如果theme没有被加载，获取不到内部组件的，因为此时 exml 文件会触发 */
    protected createChildren(): void {
        super.createChildren();
        Log.d(egret.getQualifiedClassName(this) + ":createChildren");
    }

    private onComplete(): void {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE,this.onComplete,this);
        Log.d(egret.getQualifiedClassName(this) + ":initUI");
        this.initUI();
    }
    
    /**  emxl路径 */
    protected abstract exml(): string;
    
    /** 初始化设置UI */
    protected abstract initUI(): void;

}
